<div id="app">
    <admin-page-header back>
        <bi-button icon="fa-file-archive-o" @click="post"  type="info">打包</bi-button>
        <bi-button icon="fa-list" @click="post" type="light" >历史版本</bi-button>
    </admin-page-header>

    <div class="container">
        <div class="row g-3">
            <div class="col-12">
                <bi-card title="基础信息">
                    <bi-form ref="info">
                        <bi-form-item label="应用名称">
                            <bi-input v-model="form.name" disabled required/>
                        </bi-form-item>
                        <bi-form-item label="应用标题">
                            <bi-input v-model="form.title" required placeholder="请输入应用标题" />
                        </bi-form-item>
                        <bi-form-item label="应用图标">
                            <bi-input v-model="form.icon" required placeholder="请输入应用图标" />
                        </bi-form-item>
                        <bi-form-item label="版本号">
                            <bi-input v-model="form.version" required placeholder="请输入版本号" />
                        </bi-form-item>
                        <bi-form-item label="作者">
                            <bi-input v-model="form.author"  placeholder="请输入作者" />
                        </bi-form-item>
                        
                        <bi-form-item label="版权信息">
                            <bi-input v-model="form.copyright"  placeholder="请输入版权信息" />
                        </bi-form-item>
                        <bi-form-item label="应用描述">
                            <bi-textarea v-model="form.description"  placeholder="请输入应用描述" />
                        </bi-form-item>
                        <bi-form-item label="后台首页">
                            <div class="row g-2">
                                <div class="col-6">
                                    <bi-input v-model="form.admin.controller" placeholder="Controller 控制器"/>
                                </div>
                                <div class="col-6">
                                    <bi-input v-model="form.admin.action" placeholder="Action 动作器" />
                                </div>
                            </div>
                        </bi-form-item>

                        <bi-form-item label="支持数据库" >
                            <bi-list :data="form.driverList"  v-slot="row"  type="border" dir="row" @add="addDriver" @del="delDriver"  >
                               {{row.item}}
                           </bi-list>
                       </bi-form-item>
                    </bi-form>
                    <template #footer>
                        <bi-button icon="fa-save" @click="save"  type="primary">保存</bi-button>
                    </template>
                </bi-card>
            </div>
            <div class="col-12">
                <bi-card title="数据" >
                    <model-list :app="form.name"></model-list>
             </bi-card>
            </div><div class="col-12">
                <bi-card title="插件" >
                    <plug-list :app="form.name"></plug-list>
                </bi-card>
            </div>
        </div>
        
    </div>
</div>

<script>

import modelList from 'detail/model-list.vue';
import databaseList from 'detail/database-list.vue';
import plugList from 'detail/plug-list.vue';
import addDriverDialog from 'detail/add-driver-dialog.vue';
import configList from 'detail/config-list.vue';
let app = admin.createApp({
    components:{
        modelList,
        databaseList,
        plugList,
        configList
    },
    data(){

        let form  =  {
            name:'',
            title:'',
            icon:'icon.png',
            description:'',
            author:'',
            version:'',
            copyright:'',
            
            admin:{
                controller:'',
                action:''
            },
            driverList:[
                
            ]
        }


        this.$assign(form,this.$pageData.project);
        this.$assign(form,this.$pageData.designer);

        return {
            form,
            list:[],
            loading:false
        }
    },
    methods:{
        save(){
            if (this.$refs.info.check()){
                this.$ajax({
                    url:this.$url({action:'saveInfo'}),
                    data:this.form,
                    success:(res)=>{
                        this.$toast('保存成功');
                    }
                })
            }
        },
        post(){

        },
        addDriver(){
            this.$dialog({
                type:'vue',
                content:admin.createApp(addDriverDialog,{has:this.form.driverList}),
                callback:(res)=>{
                    this.form.driverList.push(res);
                }
            });
        },
        delDriver(index,item){
            this.form.driverList.splice(index,1);
        }
    },
    mounted(){
        
    }
}).mount('#app');

</script>